package com.jh.mms.web.action;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * <li>Action基类</li>
 * <p>该类主要功能是设置一些常用的属性</p>
 * <p>取一些常用的对象：session、application、页面传过来的值等</p>
 * 
 * @author <a href="mailto:54fbj@163.com">fbj</a>
 * @version 1.0
 * @created 2012-7-27 上午1:14:43
 */
public class BaseAction extends ActionSupport{
	private static final long serialVersionUID = 7009745025135473684L;
	
	/**
	 * <li>取得ActionContext上下文对象</li>
	 *
	 * @author <a href="mailto:54fbj@163.com">fbj</a>
	 * @return ActionContext实例对象
	 * @created 2012-7-27 上午1:17:59
	 */
	public ActionContext getActionContext(){
		return ActionContext.getContext();
	}
	
	
	/**
	 * <li>以Map形式获取session对象</li>
	 *
	 * @author <a href="mailto:54fbj@163.com">fbj</a>
	 * @return <code>Map<String,Object>实例</code>
	 * @created 2012-7-27 上午1:18:32
	 */
	public Map<String,Object> getSession(){
		return getActionContext().getSession();
	}
	
	/**
	 * <li>以Map形式获取application对象</li>
	 *
	 * @author <a href="mailto:54fbj@163.com">fbj</a>
	 * @return <code>Map<String,Object>实例</code>
	 * @created 2012-7-27 上午1:20:50
	 */
	public Map<String,Object> getApplication(){
		return getActionContext().getApplication();
	}
	
	/**
	 * 
	 * <li>以Map形式获取页面传过来的参数列表</li>
	 * <li>参数的值将以字符串数组返回</li>
	 *
	 * @author <a href="mailto:54fbj@163.com">fbj</a>
	 * @return <code>Map<String,String[]>实例</code>
	 * @created 2012-7-27 上午1:21:45
	 */
	public Map<String,String[]> getParameters(){
		Map<String,Object> map = getActionContext().getParameters();
		Map<String,String[]> params = new HashMap<String,String[]>();
		for (Iterator<Entry<String, Object>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
			Entry<String, Object> en = iterator.next();
			params.put(en.getKey(), (String[])en.getValue());
		}
		return params;
	}
}
